<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@include file="/common/session.jsp" %>
<c:set var="regionId" value="${param.regionId}"/>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/MarketRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/RegionRpcService.js'></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<form id="regionForm" name="regionForm">
	<center>
        <input type="hidden" id="regionParentId" name="regionParentId" value="1">
    	<input type="hidden" id="regionState" name="regionState" value="1">
        <input type="hidden" id="regionId" name="regionId" value="${regionId}">
        <input type="hidden" id="regionRestNum" name="regionRestNum" value="">
        <table width="100%" cellpadding="5" cellspacing="5">
            <tr>
                <td>
                    所属市场:
                </td>
                <td>
                    <select id="marketId" name="marketId">
        			</select>
                </td>
            </tr>
            <tr>
                <td>
                    区域名称:
                </td>
                <td>
                    <input type="text" placeholder="区域名称(必填)" id="regionName" name="regionName" maxlength="10" required/>
                </td>
                <td>
                    地理位置:
                </td>
                <td>
                    <textarea type="text" id="regionRemark"  name="regionRemark"></textarea>
                </td>
            </tr>
            <tr>
            	<td>
                    租赁类型:
                </td>
                <td>
                    <input id="regionType1" type="radio"  name="regionType" value="1" style="width: 20px; height: 20px;" checked="checked" onclick="changeRegionType(1);"/>按面积
                    <input id="regionType2"  type="radio" name="regionType" value="2" style="width: 20px; height: 20px;" onclick="changeRegionType(2);"/>按车位
                </td>  
            </tr>
            <tr>
                <td id="label-name">
                    区域面积:
                </td>
                <td>
                    <input type="number" id="regionNum" name="regionNum"  style="width:80%"/><b id="unit-n">平米</b>
                </td>
                <td>
                    区域租金:
                </td>
                <td>
                    <input type="number" id="regionRentFee" name="regionRentFee"  style="width:80%"/><b id="unit-name">元/平米/月</b>
                </td>
            </tr>
            <tr>
                <td style="border-bottom: 1px solid #e1ecf5" colspan="6">
                </td>
            </tr>
            <tr>
                <td colspan="6" align="center">
                    <button type="button" onclick="insertOrUpdateRegion()">保存</button>
                    <button type="button" onclick="callbackRegion()">返回</button>
                </td>
            </tr>
        </table>
    </center>
</form>
</body>
</html>

<script>
    //    显示市场列表
    var market = new Market();
    market.marketId = "${marketId}";
    MarketRpcService.selectMarketList(market, callbackSelectMarketList);

    function callbackSelectMarketList(list) {
        dwr.util.addOptions("marketId", list, "marketId", "marketName");
        dwr.util.setValue("marketId", "${marketId}");
        if ("${regionId}".length > 0) {
            selectRegion();
        }
    }

    function selectRegion() {
        var region = new Region();
        region.regionId = "${regionId}";
        region.marketId = "${marketId}";
        RegionRpcService.selectRegionList(region, callbackSelectRegionList);
    }

    function callbackSelectRegionList(list) {
        dwr.util.setValues(list[0]);
    }


    function changeRegionType(i){
        if (i == 2){
            dwr.util.setValue("label-name","车位数辆:");
            dwr.util.setValue("unit-name","元/个");
            dwr.util.setValue("unit-n","个");
            clearText(i)
        }else{
            dwr.util.setValue("label-name","区域面积:");
            dwr.util.setValue("unit-name","元/平米/月");
            dwr.util.setValue("unit-n","平米");
            clearText(i)
        }
    }

    function clearText(type){
        dwr.util.setValue("regionNum","");
        dwr.util.setValue("regionRentFee","");
    }

    function insertOrUpdateRegion() {
        if (!validate($("regionForm"))) {
            return false
        }
        var region = dwr.util.getValues("regionForm");
        if ("${regionId}".length > 0) {
            RegionRpcService.updateRegion(region, callbackRegion);
        }else{
            region.regionRestNum = dwr.util.getValue("regionNum");
            RegionRpcService.insertRegion(region, callbackRegion)
        }
    }

    function callbackRegion(){
        location = "${ctx}/market/region_list.jsp";
    }

</script>
